package com.youkeyi.ddy.cloud.common.wx.applet.message.controller;

import com.youkeyi.ddy.cloud.common.enums.ResponseCodeEnum;
import com.youkeyi.ddy.cloud.common.response.ResponseObjectContent;
import com.youkeyi.ddy.cloud.common.wx.applet.message.service.impl.WxMessageServiceImpl;
import io.swagger.annotations.*;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * WxMessageController
 *
 * @Author liuxiawang
 * @Date 2024/6/28 3:03 PM
 * @Location shenzhen.china
 */
@Api(tags = {"Wx Message"})
@RestController
@RequestMapping("/system/wx")
public class WxMessageController {

    // 查询订阅的消息模版key
    @ApiOperation(value = "Query Subscribe Message Template List", authorizations = {@Authorization("com.youkeyi.ddy.cloud.common.wx.applet.message.controller.WxMessageController.subscribeMessageTemplateList")})
    @ApiResponse(code = 200, message = "data Property in Response Body", response = ResponseObjectContent.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", paramType = "query", value = "Param of Query Todo List"),
    })
    @GetMapping("/subscribe/message/template")
    public ResponseObjectContent subscribeMessageTemplateList() {
        ResponseObjectContent<List> responseObjectContent = new ResponseObjectContent<>();
        List<SubscribeMessageTemplate> subscribeMessageTemplateList = new ArrayList<>();
        Map<String, String> subscribeMessageMap = WxMessageServiceImpl.subscribeMessageMap;
        if (null != subscribeMessageMap && subscribeMessageMap.size() > 0) {
            subscribeMessageMap.forEach((k, v) -> {
                SubscribeMessageTemplate subscribeMessageTemplate = new SubscribeMessageTemplate();
                subscribeMessageTemplate.setTemplateKey(k);
                subscribeMessageTemplate.setTemplateName(WxMessageServiceImpl.subscribeMessageMapName.get(k));
                subscribeMessageTemplate.setTemplateCode(v);
                subscribeMessageTemplateList.add(subscribeMessageTemplate);
            });
        }
        responseObjectContent.setData(subscribeMessageTemplateList);
        responseObjectContent.setSuccessMessage(ResponseCodeEnum.SUCCESS.getMessage());
        return responseObjectContent;
    }

    @Data
    class SubscribeMessageTemplate {
        private String templateKey;
        private String templateName;
        private String templateCode;
    }

}
